﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using YJKCodeBase.Geometry;
using NetTopologySuite.Geometries;

namespace YJKCodeBase.TopologySuite
{
	public class HYPolygonBooleanOperater : BaseBooleanOperater
	{
		public bool TryGetOperateResult(HYPolygon inputPolygonOne, HYPolygon inputPolygonTwo, BooleanOperatorKindEnum useKind, out List<HYPolygon> creatResults)
		{
			creatResults = null;
			NtsGeometryGeter ntsGeometryGeter = NtsGeometryGeter.GetNtsGeometryGeter();
			Polygon inputGeometryOne = null;
			Polygon inputGemetryTwo = null;
			IGeometry geometry = null;
			if (!ntsGeometryGeter.TryMakePolygon(inputPolygonOne, out inputGeometryOne, true) || !ntsGeometryGeter.TryMakePolygon(inputPolygonTwo, out inputGemetryTwo, true))
			{
				return false;
			}
			if (!base.TryGetOperateResult(inputGeometryOne, inputGemetryTwo, useKind, out geometry))
			{
				return false;
			}
			if (!(geometry is Polygon) && !(geometry is MultiPolygon))
			{
				return false;
			}
			creatResults = new List<HYPolygon>();
			if (geometry is Polygon)
			{
				HYPolygon item;
				if (!NTSTransformer.TryChangePolygonToHYPolygon(geometry as Polygon, out item))
				{
					return false;
				}
				creatResults.Add(item);
			}
			else if (!NTSTransformer.TryChangePolygonToHYPolygon(geometry as MultiPolygon, out creatResults))
			{
				return false;
			}
			return true;
		}
	}
}
